Skip to content

Conversation

@sajanIocod
Copy link

Type of Change
[x] Bug fix (non-breaking change which fixes an issue)

Description
This PR addresses a critical issue where attempting to hang up or reject an incoming call while it is in the Ringing state would fail and log the error: ACTION_HANGUP is missing String EXTRA_CALL_HANDLE.

🔍 detailed Breakdown
Previous Scenario (The Bug)
Previously, the callSid variable in TwilioVoicePlugin was implemented as a computed property that queried the service directly every time it was accessed:

// Old Implementation
private val callSid: String?
get() = TVConnectionService.getActiveCallHandle()

The Issue: When a call is in the Ringing/Incoming state, the TVConnectionService often does not yet classify the call as "Active." Therefore, getActiveCallHandle() returns null. Consequently, when the user pressed "Hangup," the plugin sent an Intent with a null handle. The Service received the intent, couldn't identify which call to kill, and threw the error.

New Scenario (The Fix)
The implementation of callSid has been refactored to use local state management within the plugin.

// New Implementation
private var callSid: String? = null

The Logic:

Capture: The plugin now listens for ACTION_INCOMING_CALL (and other lifecycle events) in handleBroadcastIntent.

Store: It immediately extracts the callHandle from the broadcast intent and saves it to the local callSid variable.

Execute: When hangup() is called during the Ringing state, the plugin reads the locally stored, valid ID.

Cleanup: The callSid is reset to null upon receiving Disconnect, Reject, or Abort events.

Technical Changes
Refactored callSid from a getter to a nullable String variable.

Updated handleBroadcastIntent to set callSid on:

ACTION_INCOMING_CALL

ACTION_ANSWERED

EVENT_RINGING

EVENT_CONNECTED

Updated handleBroadcastIntent to clear callSid (set to null) on:

ACTION_CALL_ENDED

ACTION_REJECTED

ACTION_ABORT

EVENT_DISCONNECTED (Local/Remote)

EVENT_MISSED

Updated TVMethodChannels.CALL_SID to return the local variable.

bazl-E and others added 30 commits July 17, 2024 19:04
Preserve the device token for VoIP push notifications to avoid the need for users to restart the app to obtain a new device token. Removing the device token from UserDefaults caused registration failures.

fix : IOS not displaying caller number

if the user doesn't set a default caller name it will display the incoming caller number , if the already set a value user has to call [await TwilioVoice.instance.setDefaultCallerName('');] to make this work
Update the handling of the localized caller name in the `SwiftTwilioVoicePlugin.swift` file. Instead of using the `clients` dictionary to retrieve the caller name, always use the `formatUSPhoneNumber` function to format the caller's phone number. This ensures consistency and avoids potential issues with missing or incorrect caller names.

Note: This commit message follows the established convention of starting with a verb in the imperative form, followed by a concise description of the changes made.
# Conflicts:
#	android/build.gradle
#	android/src/main/kotlin/com/twilio/twilio_voice/TwilioVoicePlugin.kt
#	android/src/main/kotlin/com/twilio/twilio_voice/service/TVConnectionService.kt
#	android/src/main/kotlin/com/twilio/twilio_voice/types/TVMethodChannels.kt
#	example/ios/Runner.xcodeproj/project.pbxproj
#	ios/Classes/SwiftTwilioVoicePlugin.swift
#	ios/twilio_voice.podspec
#	lib/_internal/twilio_voice_web.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants